package com.wayhome.loadbalancer.order.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/ribbon")
public class OrderRibbonController {

    private final RestTemplate restTemplate;
    private final DiscoveryClient discoveryClient;

    private final static String STOCK_URL = "http://stock-server/";

    @GetMapping("/order/add")
    public String add() {
        String rui = STOCK_URL + "/stock/reduct";
        String result = restTemplate.getForObject(rui, String.class);
        return "新增订单" + result;
    }

    @GetMapping(value = "get/servers")
    public List<String> orderServers() {
        return discoveryClient.getServices();
    }

}
